﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SkiaSharp;
using ZXing;

namespace EasoScreen;
internal static class QRCode
{
    internal static Bitmap Generate(string content)
    {
        var writer = new BarcodeWriter<Rgba32>
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new ZXing.Common.EncodingOptions
            {
                Width = 200,
                Height = 200,
                Margin = 1
            },

        };
        var image = writer.WriteAsImageSharp<Rgba32>(content);
        using var memoryStream = new MemoryStream();
        image.Save(memoryStream, new PngEncoder());
        memoryStream.Position = 0; // Reset the stream position
        return new Bitmap(memoryStream); // Create an Avalonia Bitmap from the stream
    }
}
